using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;

namespace T.REST
{
    public class RestConfiguration
    {
        public RestConfiguration()
        {
            RequestHeader = new List<KeyValuePair<string, string>>();    
            FormsCollection = new NameValueCollection();            
        }

        /// <summary>
        /// Request header content of your HTTP request
        /// </summary>
        public List<KeyValuePair<string, string>> RequestHeader {get; set;}
        
        /// <summary>
        /// If you i.e. POST something to a web ressource you can add form variables here
        /// </summary>
        public NameValueCollection FormsCollection {get; set;}


        /// <summary>
        /// The host of your REST ressource, i.e. myapi.contoso.com. 
        /// You can declare a "host" appSetting in your app.config so you won't have to declare this property every time.
        /// Look up the documentation on http://trest.codeplex.com/documentation for details
        /// </summary>
        public string Host { get; set; }

        /// <summary>
        /// The querystring part in the ressource URL, i.e. ?foo=bar&id=4711
        /// </summary>
        public string QueryString { get; set; }
        private string _url;
        
        /// <summary>
        /// Location of your REST ressource at your host, i.e /company/contoso/leads
        /// </summary>
        public string Url
        {
            get
            {
                if (string.IsNullOrEmpty(_url))
                    throw new ArgumentException("URL not set");
                return _url.First() == '/' ? _url : "/" + _url;
            }
            set { _url = value; }
        }

        /// <summary>
        /// HTTP method used to call the ressource. Default is GET
        /// </summary>
        public string Method { get; set; }
        
        /// <summary>
        /// Should the HTTP call use SSL / HTTPS? Default is false
        /// </summary>
        public bool UseSSL {get; set;}

        /// <summary>
        /// Do you expect an array of objects to be returned? Default is false
        /// </summary>
        public bool ExpectArrayResult { get; set; }

        /// <summary>
        /// What is the expected object signature returned by the server? If ExpectArrayResult is true the first object in the returned collection will be matched against ExpectedObjectSignature
        /// </summary>
        public Dictionary<string, Type> ExpectedObjectSignature { get; set; }

        /// <summary>
        /// Username and password to authorize your call if your REST ressource requires authentication. HTTP Basic authentication only
        /// </summary>
        public KeyValuePair<string, string> Authorization { get; set; }        
    }
}